<template>
  <el-container class="home-page">
    <el-header>
        <div class="g-logo">
            <img src="@/assets/logo.png" alt=""><span>电商后台管理系统</span>
        </div>
        <el-button @click="logout" class="logout">退出</el-button>
    </el-header>
    <el-container>
      <el-aside width="200px">
        <el-menu
        :default-active="activePath"
        class="el-menu-vertical-demo"
        :unique-opened = "true"
        background-color="#333744"
        text-color="#fff"
        router
        active-text-color="#409eff">
        <!-- 一级菜单 -->
            <el-submenu class="menu-top" :index="'/'+item.path" v-for="item in menu" :key="item.id">
                <!-- 一级菜单模板区 -->
                    <template slot="title">
                        <i class="el-icon-location"></i>
                        <span>{{item.authName}}</span>
                    </template>
                    <el-menu-item :index="'/'+subitem.path" v-for="subitem in item.children" :key="subitem.id" @click="saveNavState('/'+subitem.path)">
                        <template slot="title">
                            <i class="el-icon-menu"></i>
                            <span>{{subitem.authName}}</span>
                        </template>
                    </el-menu-item>
            </el-submenu>
        </el-menu>
      </el-aside>
      <el-main>
          <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>
<script>
export default {
  name: 'Home',
  data(){
      return {
          menu:[
              {
                  id:125,
                  authName: '用户管理',
                  path: 'user',
                  children:[
                      {
                        id:126,
                        authName: '用户2',
                        path: 'user', 
                        children:[
                            {
                              id:127,
                              authName: '用户',
                              path: 'user',   
                            }
                        ]
                      }
                  ]
              },
              {
                  id:128,
                  authName: '用户权限',
                  path: 'rights',
                  children:[
                      {
                        id:129,
                        authName: '用户权限2',
                        path: 'rights', 
                        children:[
                            {
                              id:130,
                              authName: '用户权限3',
                              path: 'rights',   
                            }
                        ]
                      },
                      {
                        id:132,
                        authName: '用户角色',
                        path: 'roles',   
                      }
                  ]
              }
          ],
          // 被激活的动态地址
          activePath: ''
      }
  },
  created(){
    this.activePath = window.sessionStorage.getItem('activePath')
  },
  computed: {

  },
  methods: {
    logout() {
      window.sessionStorage.clear()
      this.$router.push('/login')
    },
    // 保存链接的激活状态
    saveNavState(activePath){
      window.sessionStorage.setItem('activePath', activePath)
    }
  }
}
</script>
<style lang='less' scoped>
.home-page{
    height: 100vh;
}
.el-header{
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.el-header,
.el-footer {
  background-color: #373d41;
  text-align: center;
  line-height: 60px;
}
.g-logo{
    color: #FFF;
    font-size: 24px;
    display: flex;
    align-items: center;
}
.g-logo img{
    height: 40px;
    margin-right: 10px;
}
.logout{
    height: 60%;
}

.el-aside {
  background-color: #333744;
  color: #333;
  text-align: center;
  line-height: 200px;
  .el-menu{
        border: none;
    }
}

.el-main {
    background: #fafafa;
}
.menu-top{
    text-align: left;
}
</style>